<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title></title>
    <script src="../js/require.js"></script>
    <script src="./js/requireConfig.js"></script>
    <link rel="stylesheet" href="../js/Cesium/1.65/Build/Cesium/Widgets/widgets.css">
    <link rel="stylesheet" href="../css/common.css">
    <script>

        require([
            "uMap/uMap",
            "uEarth/uEarth",
            "mhjs/mhjs"
        ], function (uMap, uEarth, mhjs) {

            var earth = new uMap.Earth({
                objectOption: {
                    "container": "uMapApp_earthContainer"
                }
            });

            var debug = {};
            debug.transformPanel = new uMap.TransformPanel({
                "earth"     : earth,
                "title"     : "模型位置调整",
                "showClose" : true,
                "showSubmit": true,
                "submitText": "复制变形参数到剪贴板"
            });

            debug.transformPanel.on("submit", function (panel) {
                uMap.Clipboard(panel.transform.value);
            });

            debug.transformPanel.hide();
            $("body").append(debug.transformPanel.dom);

            //地球设置
            earth.scene.globe.depthTestAgainstTerrain = true;
            earth.scene.postProcessStages.fxaa.enabled = false;

            //固定光照
            earth.clock.currentTime = uEarth.JulianDate.fromDate(new Date("2020/01/01 10:00:00"));
            earth.clock.clockRange = uEarth.ClockRange.CLAMPED;
            earth.clock.shouldAnimate = false;


            earth.imageryLayers.add(
                new uMap.ImageryLayer({
                    objectOption: {
                        imageryProvider: new uEarth.UrlTemplateImageryProvider({
                            url         : "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
                            maximumLevel: 17
                        })
                    }
                }).object
            );

            var OPModelTileSet = new uMap.ObliquePhotographyModelPrimitive({
                objectOption: {
                    "url"                    : "data/bim/0912/0913/tileset.json",
                    "maximumScreenSpaceError": 1
                },
                "transform" : {
                    "position": {
                        "longitude": 120.51408475186852,
                        "latitude" : 30.976228059981757,
                        "height"   : 0
                    },
                    "type"    : "local"
                }
            });

            OPModelTileSet.on("loaded", function (tileSet) {
                earth.camera.flyToBoundingSphere(
                    tileSet.boundingSphere
                );

                debug.transformPanel.transform = tileSet.transform;
                debug.transformPanel.show();

                OPModelTileSet.on("click", function (event) {

                    if (event.pickObject) {

                        var feature = event.pickObject;

                        // console.log(feature);
                        // console.log("Class: " + feature.getExactClassName());

                        console.clear();
                        console.log("Properties:");
                        var propertyNames = feature.getPropertyNames();
                        var length = propertyNames.length;
                        for (var i = 0; i < length; ++i) {
                            var name = propertyNames[i];
                            var value = feature.getProperty(name);
                            console.log("  " + name + ": " + value);
                        }

                        if (feature.getProperty("DbId")) {
                            $.get("data/bim/0912/0913/info/" + parseInt(feature.getProperty("DbId") / 100) + ".json", function (json) {

                                if (json.data && json.data[feature.getProperty("DbId")]) {
                                    var properties = json.data[feature.getProperty("DbId")];
                                    console.log(properties.categories[6].props.values[0]);
                                }

                            });
                        }

                    }

                });

            });

            earth.scene.primitives.add(OPModelTileSet.object);


        });
    </script>

</head>
<body>
<div id="uMapApp_earthContainer" class="uMapApp_earthContainer"></div>
</body>
</html>